package main

import "fmt"

// 案例1
func case1() {
	foo := func() {
		fmt.Println("I am function foo1")
	}
	defer foo()
	foo = func() {
		fmt.Println("I am function foo2")
	}
}

// 案例2
func case2() {
	x := 10
	defer func(a int) {
		fmt.Println(a)
	}(x)
	x++
}

// 案例3
func main() {
	x := 10
	defer func() {
		fmt.Println(x) // 保留x的地址
	}()
	x++
}
